package com.zhuguowei.permissiondemo;

import android.Manifest;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;

import com.zhuguowei.permissiondemo.utils.PermissionUtils;
import com.zhuguowei.permissiondemo.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.tv_text)
    TextView mTvText;
    @BindView(R.id.btn_camera)
    Button mBtnCamera;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.btn_camera)
    public void onViewClicked() {
        PermissionUtils.requestPermissions(this, 1, new String[]{Manifest.permission.CAMERA}, new PermissionUtils.OnPermissionListener() {
            @Override
            public void onPermissionGranted() {
                //已经获取该权限
                ToastUtils.showLong("已获取权限");
            }

            @Override
            public void onPermissionDenied(String[] deniedPermissions) {
                ToastUtils.showLong("权限拒绝：" + deniedPermissions);
            }
        }, new PermissionUtils.RationaleHandler() {
            @Override
            protected void showRationale() {
                PermissionUtils.showMissingPermissionDialog();
            }
        });
    }


}
